package com.urbanski.clipboard.server.action.message;

import java.io.IOException;
import org.apache.log4j.Logger;
import com.urbanski.clipboard.common.message.EmptyResponse;
import com.urbanski.clipboard.common.message.Message;
import com.urbanski.clipboard.server.ClientSocket;
import com.urbanski.clipboard.server.ClipboardServer;
import com.urbanski.util.logging.LoggingUtil;

public class DisconnectMessageHandler extends ServerMessageHandler
{
	private static final Logger LOGGER = Logger.getLogger(DisconnectMessageHandler.class);

	public DisconnectMessageHandler(ClientSocket client)
	{
		super(client);
	}

	@Override
	public void handle(Message message)
	{
		try
		{
			client.sendResponse(new EmptyResponse());
		}
		catch (IOException e)
		{
			LoggingUtil.logAndPrintError(LOGGER, "Error sending response to client", e);
		}
		System.out.println(client.getClientName() + " disconnecting");
		ClipboardServer.removeClient(client);
	}

}
